package com.lemon.smartsafety.ui.adapter.notice;

import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.notice.NoticeReaderVo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class NoticeSentDetailAdapter extends LemonRcvAdapter<NoticeReaderVo> {
    private RecyclerTClickListener<NoticeReaderVo> mListener;

    public NoticeSentDetailAdapter(@Nullable List<NoticeReaderVo> data) {
        super(data);
    }

    public NoticeSentDetailAdapter(List<NoticeReaderVo> data, RecyclerTClickListener<NoticeReaderVo> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new NoticeSentDetailItem();
    }

    public class NoticeSentDetailItem implements AdapterItem<NoticeReaderVo> {

        LinearLayout   ripple;
        TextView     tvName;
        TextView     tvUnit;
        LinearLayout llPost;
        TextView     tvPost;
        LinearLayout llPhone;
        TextView     tvPhone;
        LinearLayout llReadTime;
        TextView     tvReadTime;


        private NoticeReaderVo mData;
        private int            mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_notice_sent_detail_list;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            tvName = (TextView) root.findViewById(R.id.tv_name);
            tvUnit = (TextView) root.findViewById(R.id.tv_unit);
            llPost = (LinearLayout) root.findViewById(R.id.ll_post);
            tvPost = (TextView) root.findViewById(R.id.tv_post);
            llPhone = (LinearLayout) root.findViewById(R.id.ll_phone);
            tvPhone = (TextView) root.findViewById(R.id.tv_phone);
            llReadTime = (LinearLayout) root.findViewById(R.id.ll_read_time);
            tvReadTime = (TextView) root.findViewById(R.id.tv_read_time);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });
    /*        ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(NoticeReaderVo data, int position) {
            mData = data;
            mPosition = position;

            tvName.setText(StringUtils.nullValue(data.getUserName()));

            tvUnit.setText(StringUtils.nullValue(data.getUnitName()));

            String sPost = StringUtils.nullValue(data.getRole());
            if (sPost.length() == 0) {
                llPost.setVisibility(View.GONE);
            } else {
                llPost.setVisibility(View.VISIBLE);
                tvPost.setText(sPost);
            }
            String phoneNumber = StringUtils.nullValue(data.getMobile(), "--");
            tvPhone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
            tvPhone.setText(phoneNumber);
            if (StringUtils.nullValue(data.getMobile()).length() == 0) {
                ripple.setEnabled(false);
            }else{
                ripple.setEnabled(true);
            }


            String sReadTime = StringUtils.nullValue(data.getReadDate());
            if (sReadTime.length() == 0) {
                llReadTime.setVisibility(View.GONE);
            } else {
                llReadTime.setVisibility(View.VISIBLE);
                tvReadTime.setText(sReadTime);
            }
        }
    }
}
